﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight.Threading;
using MyMeetup.Entities;

namespace MyMeetup
{
    public static class ResponseHelper
    {
        public static string GetQueryParameter(string content, string key)
        {
            //oauth_token=6da869bc9d4dc26756d3db9b8f06403d&oauth_token_secret=ecfa9aed428bc09c13bf12fb63917ea5&oauth_callback_confirmed=true"
            if (!content.Contains(key)) return "";
            foreach (var s in content.Split('&'))
            {
                if (s.Contains(key + "="))
                    return s.Split('=')[1];
            }
            return "";
        }

        public static void ErrorCallback(RequestError error)
        {
            if (error == null)
            {
                error = new RequestError()
                            {details = "There was a problem connecting to meetup.com", problem = "Network Error"};
            }

            DispatcherHelper.Initialize();
            DispatcherHelper.CheckBeginInvokeOnUI(
                () =>
                    {
                        GlobalLoading.Instance.IsLoading = false;
                        MessageBox.Show(error.details,
                                        error.problem, MessageBoxButton.OK);
                    });
        }

    }
}
